home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MISC / SHELL.ARC / Shell / h / Extra < prev    next >
Encoding:
Text File  |  1994-09-24  |  8.4 KB  |  284 lines

  1. /* Some extra routines which may be useful...                */
  2. /* They are for implementing a non-standard rectangle type, i.e.    */
  3. /* when you call Shell_AddRectangle yourself instead of         */
  4. /* Shell_AddBarGraph, Shell_AddGeneralArray, ... etc. When you do this    */
  5. /* you have to write a redrawing function, for which many of the     */
  6. /* following functions are useful.                    */
  7. /* The supplied rectangle funtions such as BarGraph, Array etc. use     */
  8. /* these functions, so look at the source for examples.            */
  9.  
  10.  
  11. #ifndef __Shell_Extra_h
  12. #define __Shell_Extra_h
  13.  
  14. #ifndef __Shell_h
  15. #include "Shell.Shell.h"
  16. #endif
  17.  
  18. #ifndef __dl_gfx_h
  19. #include "DeskLib:GFX.h"
  20. #endif
  21.  
  22. #ifndef __dl_colourtrans_h
  23. #include "DeskLib:ColourTran.h"
  24. #endif
  25.  
  26.  
  27. BOOL Shell_CheckYScrollIsBottom( window_handle windowhandle);
  28.     /* Returns TRUE if windowhandle y-scrollbar is at bottom    */
  29.  
  30. void Shell_MoveYScrollToBottom( window_handle window);
  31.     /* Moves y-scrollbar to bottom                    */
  32.  
  33. #define Shell_MakeGE( a, b)  if ((b) > (a)) (a) = (b)
  34. #define Shell_MakeLE( a, b)  if ((b) < (a)) (a) = (b)
  35.     /* These macros change the *first* parameter so that it    */
  36.     /* is >= or <= the second parameter.            */
  37.     /* Useful when you are clipping rectangles.        */
  38.  
  39.  
  40. void Shell_ConvertToTextRect( wimp_rect *rect);
  41.     /* divides all x's and y's by Shell_TEXTXSIZE, Shell_TEXTYSIZE    */
  42.  
  43. void Shell_ConvertToSubTextRect( wimp_rect *rect, const wimp_rect *bigrect);
  44.     /* Used in 2D array rectangle routines.                */
  45.     /* bigrect encloses total array, this routine makes *rect     */
  46.     /* contain line and column of rect inside bigrect        */
  47.  
  48. void Shell_ConvertToSubTextRect2( wimp_rect *rect, wimp_point rectsize);
  49.     /* As above, but uses a size for the bigrect, for the new     */
  50.     /* redrawing method where the redrawer works relative to the     */
  51.     /* bottom-left of the rectblock.                */
  52.  
  53.  
  54.  
  55.  
  56. void Shell_CheckWindSizeAndRedraw( window_handle window, const wimp_rect *rect);
  57.     /* Checks that *rect is inside current size of window, and     */
  58.     /* resizes the window if nessary. Then does a Wimp_ForceRedraw     */
  59.     /* if any of rect is currently visible, or the window has been     */
  60.     /* resized.                            */
  61.     /* This is used by Shell_AddRectangle.                */
  62.  
  63. void Shell_CheckWindSizeAndRedrawAndScroll( window_handle window, const wimp_rect *rect);
  64.     /* As above, but also keeps scroll at lower limit if it is     */
  65.     /* already there                        */
  66.  
  67. void Shell_ResizeIconRect( Shell_rectblock *r);
  68.     /* Makes a rect's icon-rect the appropriate size    */
  69.     /* for the rect's rect. This function should be called    */
  70.     /* whenever a rect is resized.                */
  71.     /* When redrawing rects, the iconrect is checked     */
  72.     /* against the redraw rect so that any icon-border    */
  73.     /* is redrawn correctly.                */
  74.  
  75.  
  76.  
  77.  
  78. /* Low level routines for use in rectangle redrawing functions        */
  79. /* -----------------------------------------------------------        */
  80. /* They enable you to print text, fill rectangles etc inside windows,     */
  81. /* but without having to convert everything to screen coors.        */
  82.  
  83.  
  84. /* These next few functions/#defines are equivalent to GFX_ calls,     */
  85. /* except you pass them a convert_block, and they deal with the scroll    */
  86. /* bars, window position, etc.                        */
  87.  
  88.  
  89. #define Shell_ConvertXToScreen( xx, convert)    ( (xx) + (convert).x)
  90. #define Shell_ConvertYToScreen( yy, convert)    ( (yy) + (convert).y)
  91.  
  92. #define Shell_ConvertXToWorkarea( xx, convert)    ( (xx) - (convert).x)
  93. #define Shell_ConvertYToWorkarea( yy, convert)    ( (yy) - (convert).y)
  94.  
  95. #define Shell_ConvertRectToWorkarea( rect, convert)    {    \
  96.     (rect)->min.x -= (convert).x;                \
  97.     (rect)->max.x -= (convert).x;                \
  98.     (rect)->min.y -= (convert).y;                \
  99.     (rect)->max.y -= (convert).y;                \
  100.     }                            \
  101.  
  102. #define Shell_ConvertRectToScreen( rect, convert)    {    \
  103.     (rect)->min.x += (convert).x;                \
  104.     (rect)->max.x += (convert).x;                \
  105.     (rect)->min.y += (convert).y;                \
  106.     (rect)->max.y += (convert).y;                \
  107.     }                            \
  108.  
  109.  
  110. void    Shell_RectangleFill( const wimp_rect *rect, Shell_convertpoint convert);
  111.  
  112. void    Shell_RectangleFill3( int x, int y, int width, int height, Shell_convertpoint convert);
  113.  
  114. void    Shell_RectangleFill2( int xmin, int ymin, int xmax, int ymax, Shell_convertpoint convert);
  115.  
  116.  
  117.  
  118. #define Shell_RectangleFill_16bit( rect, convert)            \
  119.     GFX_RectangleFill(                    \
  120.         Shell_ConvertXToScreen( rect->min.x, convert),    \
  121.         Shell_ConvertYToScreen( rect->min.y, convert),    \
  122.         rect->max.x - rect->min.x,            \
  123.         rect->max.y - rect->min.y            \
  124.         )                        \
  125.  
  126.  
  127.  
  128. #define Shell_RectangleFill2_16bit( xmin, ymin, xmax, ymax, convert)    \
  129.     GFX_RectangleFill(                    \
  130.         Shell_ConvertXToScreen( xmin, convert),        \
  131.         Shell_ConvertYToScreen( ymin, convert),        \
  132.         xmax - xmin,                    \
  133.         ymax - ymin                    \
  134.         )                        \
  135.  
  136.  
  137. #define Shell_RectangleFill3_16bit( xmin, ymin, width, height, convert)    \
  138.     GFX_RectangleFill(                        \
  139.         Shell_ConvertXToScreen( xmin, convert),            \
  140.         Shell_ConvertYToScreen( ymin, convert),            \
  141.         width,                            \
  142.         height                            \
  143.         )                            \
  144.  
  145.  
  146. #define Shell_GFX_ParallelFill( x1, y1, x2, y2, x3, y3)                \
  147.     do    {                                \
  148.         GFX_Move( x1, y1);                        \
  149.         GFX_Move( x2, y2);                        \
  150.         GFX_Plot( plot_DRAWABSFORE + plot_PARALLELFILL, x3, y3);    \
  151.         }                                \
  152.         while (0)                            \
  153.     /* See below.    */
  154.  
  155. #define Shell_GFX_ParallelFillBy( x1, y1, dx2, dy2, dx3, dy3)            \
  156.     do    {                                \
  157.         GFX_Move( x1, y1);                        \
  158.         GFX_MoveBy( dx2, dy2);                        \
  159.         GFX_Plot( plot_DRAWRELFORE + plot_PARALLELFILL, dx3, dy3);    \
  160.         }                                \
  161.         while (0)                            \
  162.     /* See below.    */
  163.  
  164.  
  165. #define Shell_ParallelFill( x1, y1, x2, y2, x3, y3, convert)    \
  166.     Shell_GFX_ParallelFill(                    \
  167.         Shell_ConvertXToScreen( x1, convert),        \
  168.         Shell_ConvertYToScreen( y1, convert),        \
  169.         Shell_ConvertXToScreen( x2, convert),        \
  170.         Shell_ConvertYToScreen( y2, convert),        \
  171.         Shell_ConvertXToScreen( x3, convert),        \
  172.         Shell_ConvertYToScreen( y3, convert)        \
  173.         )                        \
  174.     /* Draws a parallelogram with (x1,y1) and (x3,y3) being opposite corners    */
  175.     /* and (x2,y2) one of the other corners.                    */
  176.  
  177. #define Shell_ParallelFillBy( x1, y1, dx2, dy2, dx3, dy3, convert)    \
  178.     Shell_GFX_ParallelFillBy(                        \
  179.         Shell_ConvertXToScreen( x1, convert),            \
  180.         Shell_ConvertYToScreen( y1, convert),            \
  181.         dx2, dy2,                        \
  182.         dx3, dy3                        \
  183.         )                            \
  184.     /* Draws a parallelogram with one corner being (x1,y1), one of its neighbers    */
  185.     /* being (x1+dx2,y1+dy2), and the opposite corner to (x1,y1) being        */
  186.     /* (x1+dx2+dx3,y1+dy2+dy3).                            */
  187.  
  188.  
  189.  
  190. #define Shell_Draw2( x, y, convert)            \
  191.     GFX_Draw(                    \
  192.         Shell_ConvertXToScreen( x, convert),     \
  193.         Shell_ConvertYToScreen( y, convert)    \
  194.         )                    \
  195.  
  196. #define Shell_Move( x, y, convert)            \
  197.     GFX_Move(                    \
  198.         Shell_ConvertXToScreen( x, convert),     \
  199.         Shell_ConvertYToScreen( y, convert)    \
  200.         )                    \
  201.  
  202.  
  203.  
  204. #define Shell_PlotPoint( x, y, convert)            \
  205.     GFX_PlotPoint(                    \
  206.         Shell_ConvertXToScreen( x, convert),     \
  207.         Shell_ConvertYToScreen( y, convert)    \
  208.         )                    \
  209.  
  210.  
  211. #define Shell_Circle( x, y, r, convert)            \
  212.     GFX_Circle(                    \
  213.         Shell_ConvertXToScreen( x, convert),     \
  214.         Shell_ConvertYToScreen( y, convert),    \
  215.         r                    \
  216.         )                    \
  217.  
  218. #define Shell_CircleFill( x, y, r, convert)        \
  219.     GFX_CircleFill(                    \
  220.         Shell_ConvertXToScreen( x, convert),     \
  221.         Shell_ConvertYToScreen( y, convert),    \
  222.         r                    \
  223.         )                    \
  224.  
  225.  
  226.  
  227.  
  228.  
  229. #define    Shell_Plot( plotcode, x, y, convert)    \
  230.     GFX_Plot(                \
  231.         plotcode,             \
  232.         Shell_ConvertXToScreen( x),    \
  233.         Shell_ConvertYToScreen( y)    \
  234.         )                \
  235.  
  236.     /* A general OS_Plot routine                    */
  237.  
  238.  
  239.  
  240. /*
  241. void Shell_PrintString( const char *s, int x, int y, const Shell_convertpoint convert);
  242. */
  243.     /* Low level non-wimp print routine to print text straight     */
  244.     /* onto screen. x and y should be in work-area coors.        */
  245.     /* Used in rectangle-redrawing routines to print text without     */
  246.     /* having to convert explicitly to screen coors.        */
  247.  
  248. #define Shell_PrintString( text, x, y, convert)                \
  249.     do    {                            \
  250.     GFX_Move(                             \
  251.         Shell_ConvertXToScreen( x, convert),             \
  252.         Shell_ConvertYToScreen( y, convert) - Shell_PIXELYSIZE    \
  253.         );                            \
  254.     GFX_Write0( text);                        \
  255.     }                                \
  256.     while (0)                            \
  257.  
  258.     /* The do...while bit is so Shell_PrintString looks like a real function.    */
  259.     /* i.e. you put a semicolon after it.                        */
  260.  
  261.  
  262.  
  263. void Shell_ConvertToSubRect( wimp_rect *rect, const wimp_rect *bigrect);
  264.  
  265. void Shell_ConvertToSubRect2( wimp_rect *rect, wimp_point bigsize);
  266.  
  267.  
  268. #define Shell_SetGreyGCOL( x)                    \
  269.     ColourTrans_SetGCOL(                     \
  270.         (( (int) ((x)*255.999)) << 8) |            \
  271.         (( (int) ((x)*255.999)) << 16) |             \
  272.         (( (int) ((x)*255.999)) << 24),            \
  273.         1<<8,            /* Use ECFs    */    \
  274.         0            /* gcol action    */    \
  275.         )                        \
  276.     /* 'x' should be a brightness between 0 and 1. This uses a    */
  277.     /* ColourTrans call to set the GCOL colour to a grey of the     */
  278.     /* appropriate brightness.                    */
  279.     /* It should be fairly obvious how it works...            */
  280.  
  281.  
  282.  
  283. #endif
  284.